<template>
  <div style="padding: 30px">
    <div style="text-align: end">
      <el-button type="text" icon="el-icon-switch-button" @click="cancellation"
        >注销</el-button
      >
    </div>
    <el-form
      ref="infoForm"
      :model="infoForm"
      label-width="130px"
      style="margin: 10px 0"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="主机名称">
            <el-input
              v-model="infoForm.pcName"
              placeholder="请输入主机名称"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="资产编号">
            <el-input
              v-model="infoForm.AssetNo"
              placeholder="请输入资产编号"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="操作系统">
            <el-input
              v-model="infoForm.os"
              placeholder="请输入操作系统"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="CPU">
            <el-input
              v-model="infoForm.cpuModel"
              placeholder="请输入CPU"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="MAC地址">
            <el-input
              v-model="infoForm.mac"
              placeholder="请输入MAC地址"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="ip地址">
            <el-input
              v-model="infoForm.ip"
              placeholder="请输入ip地址"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位">
            <el-input
              v-model="infoForm.UnitName"
              placeholder="请输入单位"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门">
            <el-input
              v-model="infoForm.DeptName"
              placeholder="请输入部门"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="责任人">
            <el-input
              v-model="infoForm.EmpName"
              placeholder="请输入责任人"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="密级">
            <el-select
              v-model="infoForm.SecLvl"
              placeholder="请选择密级"
              disabled
            >
              <el-option label="非密" value="1"></el-option>
              <el-option label="秘密" value="2"></el-option>
              <el-option label="机密" value="3"></el-option>
              <el-option label="绝密" value="4"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="系统账户">
            <el-input
              v-model="infoForm.accountList"
              disabled
              placeholder="请输入系统账户"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <div style="text-align:center">
        <el-button type="primary" @click="addForm">确 认</el-button>
        <el-button>取 消</el-button>
      </div> -->
    </el-form>
  </div>
</template>
<script>
export default {
  name: "mabDevice",
  data() {
    return {
      infoForm: {
        pcName: "",
        AssetNo: "",
        os: "",
        cpuModel: "",
        mac: "",
        ip: "",
        UnitName: "23",
        DeptName: "",
        DeptID: "",
        UnitID: "",
        EmpName: "",
        EmpID: "1",
        SecLvl: "1",
        Machine: "",
        HostType: "1", //0-网络版在线注册 1-单机版 2-网络版离线注册
        accountList: "",
      },
    };
  },
  created() {
    this.getForm();
  },
  methods: {
    cancellation() {
      let than = this;
      this.$confirm(
        "您将注销，部分数据将清空，取消后需要再次注册才能继续使用，请确认是否要取消注册！",
        "注销",
        {
          confirmButtonText: "是",
          cancelButtonText: "否",
          type: "warning",
        }
      )
        .then(() => {
          let data = {
            data: 1,
          };
          this.$postForJson("/vgmp/config/unregister", data).then((res) => {
            console.log(res);
            if (res.data.errorcode == "0") {
              this.$message({
                type: "success",
                message: "注销成功!",
              });
              //  调注销后重启客户端接口
              this.$get("/bdgl/config/reset").then((res1) => {
                console.log(res1, 157);
                if (res1.data.errorcode == "0") {
                  this.$message({
                    type: "success",
                    message: "重启客户端成功",
                  });
                  //  注销成功调注册页面
                  than.$router.push("/install");
                } else {
                  this.$message({
                    type: "error",
                    message: res1.data.errormsg,
                  });
                }
              });
            } else {
              this.$message({
                type: "error",
                message: res.data.errormsg,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消注销",
          });
        });
    },
    addForm() {
      // let params = {};
      // for (let item in this.infoForm) {
      //   if (this.infoForm[item]) {
      //     params[item] = this.infoForm[item];
      //   }
      // }
      this.$postForJson("vgmp/config/register", { data: this.infoForm }).then(
        (res) => {
          let { result, tip } = res.data;

          this.$alert("保存成功！", "提示", {
            confirmButtonText: "确定",
            type: "primary",
          })
            .then(() => {
              this.$emit("product");
            })
            .catch(() => {});
        }
      );
    },
    getForm() {
      this.$get("/vgmp/config/gethostinfo").then((res) => {
        let { data } = res.data;
        this.infoForm = {
          DeptID: data.deptId,
          DeptName: data.deptName,
          UnitID: data.unitId,
          EmpName: data.empName,
          SecLvl: data.secLevel,
          Machine: data.machine,
          AssetNo: data.assetNum,
          AddressInfo: data.addressInfo,
          HostType: data.hostType, //0-网络版在线注册 1-单机版 2-网络版离线注册
          EmpID: data.empId,
          UnitName: data.unitName,
          licenseModel: data.licenseModel,
          os: data.os,
          pcName: data.pcName,
          cpuModel: data.cpuModel,
          ip: data.ip,
          mac: data.mac,
        };
        let val = "";
        data.accountList.forEach((item) => {
          val += item.accountInfo.account + ",";
        });
        this.infoForm.accountList = val.slice(0, val.lastIndexOf(","));
      });
    },
  },
};
</script>

<style scoped></style>
